< previous page page_363 next page >

Page 363
It is ultimately possible to handle any structure, no matter what type of data it contains. At the very worst, you can allocate your own memory buffer and copy data into the buffer in the format required.
Strings in Structures
The first issue to consider with regard to strings inside structures follows from the fact that Visual Basic uses Unicode characters internally. Strings inside structures are stored within Visual Basic in Unicode format.
The Struct.vbp project can be used to help understand what is going on within Visual Basic during a DLL call. The project defines the following structure:
Private Type Struct1
   a As Integer
   b As Integer
   c As String * 4
   d As String
End Type
The project contains the function ShowMemory, which takes a memory address as a parameter and prints the contents of a specified number of bytes in hexadecimal format. We'll be using this function to analyze the contents of memory buffers for the structure.
' Display the bytes of memory at the address specified in
' hexadecimal format.
Private Sub ShowMemory(ByVal Address As Long, ByVal bytes As Integer)
   Dim b As Byte
   Dim x As Integer
   ' Print the address
   Debug.Print Hex$(Address) & ": ";
   ' Copy each byte in the buffer one byte at a time into
   ' a temporary variable 'b'
   For x = 0 To bytes - 1
      Call RtlMoveMemory(b, ByVal Address + x, 1)
      ' Display the hex value of byte 'b'
      Debug.Print Hex$(b) & " ";
   Next x
   Debug. Print
End Sub

 
< previous page page_363 next page >